package com.dq.rbac.commons.exception;

import com.dq.rbac.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @project: rbac
 * @ClassName: 全局异常捕获并且返回前端JSON格式
 * @author: dq
 * @creat: 2022/12/26 15:25
 */
@RestControllerAdvice
@Slf4j
public class GlobalSystemExceptionHandler {
    //统一异常捕获处理
    @ExceptionHandler(Exception.class)
    public R handlerRuntimeException(Exception e) {
        log.error("--------------------------------------------");
        log.error("运行时异常 报错时间     --------{}", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        log.error("运行时异常 全局异常捕获  --------{}", e.getMessage());
        log.error("--------------------------------------------");
        return R.error().message(e.getMessage());
    }
}
